package com.tedu;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tedu.mapper.UserMapper;
import com.tedu.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试
 */
public class SpringTest {
    public static void main(String[] args) {
        //加载spring，启动spring
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        //获取UserMapper对象
        UserMapper bean = ac.getBean(UserMapper.class);
        //对应查询方法
        List<User> users = bean.selectList(null);
        System.out.println(users);
        //按条件查询
        List<Integer> ids = new ArrayList<>();
        ids.add(14);
        ids.add(15);
        ids.add(16);
        List<User> users1 = bean.selectBatchIds(ids);//通过id集合查询多条
        System.out.println(users1);

        Map<String,Object> map = new HashMap<>();
        map.put("password","126");
        List<User> users2 = bean.selectByMap(map);// 通过查询条件+map中，进行
        System.out.println(users2);

        //通过Wrapper对象  多条件查询
        Wrapper<User> wrapper = new QueryWrapper<>();
        User user = new User();
        user.setId(15);

        List<User> users3 = bean.selectList(wrapper);
        System.out.println(users3);
        //大家练习一下以上几个查询方法  5
    }
}
